
message = document.getElementById("Message");
function call_on_change(){
    var pnrnumber = document.PnrForm.pnrnumber.value;
    var pnr_numify = pnrnumber.replace("-", "");
    if (pnrnumber == ""){
        message.innerHTML = "<span class='LiteText'>(Enter your PNR number here)</span>";
        document.getElementById("Button").disabled = true;
        }
    else if (/^[0-9-]+$/.test(pnrnumber) && pnr_numify.length <=10){
        message.innerHTML = "<span class='CorrectText'>Enter your 10-digit pnrnumber</span>";
        document.getElementById("Button").disabled = true;
    }
    else {
        message.innerHTML = "<span class='AlertText'> Invalid PNR Number </span>";
        document.getElementById("Button").disabled = true;
    }
    if(/^[0-9-]+$/.test(pnrnumber) && pnr_numify.length == 10){
        document.getElementById("Button").disabled = false;
        message.innerHTML = "<span class='CorrectText'>Click on Check Status</span>";
    }
    setTimeout("call_on_change()", 500)
}

function change_value(input, month, day, train_details) {
    var xhr=null;

    if (window.XMLHttpRequest) {
        xhr = new XMLHttpRequest();
    }
    else if (window.ActiveXObject)
    {
        xhr = new ActiveXObject("Microsoft.XMLHTTP");
    }
    
    xhr.onreadystatechange = function() { alert_ajax(xhr,input); };

    document.getElementById("message").className="seeme";

    select  = document.getElementById(input);
    klass = select.value;
    url = "enquiry?month="+month+"&day="+day+"&train_details="+train_details+"&klass="+klass;
    xhr.open("GET",url,true);
    xhr.send(null);
}

function alert_ajax(xhr,input)
{
    anchor = document.getElementsByName(input)[0];
    anchor.innerHTML= "<img src='http://www.90di.com/travel/image/InProgress-big.gif'>";

    if (xhr.readyState=='4')
    {
        var docXML= xhr.responseText;
	klass = document.getElementById(input).value;
	anchor.removeAttribute('href');
	anchor.innerHTML= ""+klass+"<br/1>"+docXML+"";
    }
}

function change_select(select,num,month,day,details) {
    var value = "javascript: change_value('"+num+"','"+month+"','"+day+"','"+details+"')";
    anchor = document.getElementsByName(select.id)[0];
    anchor.setAttribute("href",value);
    anchor.innerHTML = "check availability";
}
